{template 'common/header'}

<ul class="nav nav-tabs">

	<li {if $operation == 'post'}class="active"{/if}><a href="{php echo $this->createWebUrl('classify', array('op' => 'post'))}">添加分类</a></li>

	<li {if $operation == 'display'}class="active"{/if}><a href="{php echo $this->createWebUrl('classify', array('op' => 'display'))}">管理分类</a></li>

</ul>

<script>

	require(['bootstrap'],function($){

		$('.btn').hover(function(){

			$(this).tooltip('show');

		},function(){

			$(this).tooltip('hide');

		});

	});

</script>

{if $operation == 'post'}

<div class="main">

	<form action="" method="post" class="form-horizontal form" enctype="multipart/form-data" id="form1">

		<div class="panel panel-default">

			<div class="panel-heading">

				商品分类(最多添加8个分类)

			</div>

			<div class="panel-body">

				{if !empty($parentid)}

				<div class="form-group">

					<label class="col-xs-12 col-sm-3 col-md-2 control-label">上级分类</label>

					<div class="col-sm-9 col-xs-12 control-label" style="text-align:left;">{$parent['name']}</div>

				</div>

				{/if}

				<div class="form-group">

					<label class="col-xs-12 col-sm-3 col-md-2 control-label">排序</label>

					<div class="col-sm-9 col-xs-12">

						<input type="text" name="displayorder" class="form-control" value="{$category['displayorder']}" />

					</div>

				</div>

				<div class="form-group">

					<label class="col-xs-12 col-sm-3 col-md-2 control-label"><span style="color:red">*</span>分类名称</label>

					<div class="col-sm-9 col-xs-12">

						<input type="text" name="catename" class="form-control" value="{$category['name']}" />

					</div>

				</div>
				<div class="form-group">

					<label class="col-xs-12 col-sm-3 col-md-2 control-label">分类描述</label>

					<div class="col-sm-9 col-xs-12">

						<input type="text" name="description" class="form-control" value="{$category['description']}" />

					</div>

				</div>

				<div class="form-group">

					<label class="col-xs-12 col-sm-3 col-md-2 control-label">分类图片</label>

					<div class="col-sm-9 col-xs-12">

						{php echo tpl_form_field_image('thumb', $category['thumb']);}

					</div>

				</div>
				<div class="form-group">

					<label class="col-xs-12 col-sm-3 col-md-2 control-label">选中图片</label>

					<div class="col-sm-9 col-xs-12">

						{php echo tpl_form_field_image('thumb2', $category['thumb2']);}

					</div>

				</div>

				<div class="form-group">

					<label class="col-xs-12 col-sm-3 col-md-2 control-label">是否显示</label>

					<div class="col-sm-9 col-xs-12">

						<label class='radio-inline'>

							<input type='radio' name='enabled' value=1 {if $category['enabled']==1}checked{/if} /> 是

						</label>

						<label class='radio-inline'>

							<input type='radio' name='enabled' value=0 {if $category['enabled']==0}checked{/if} /> 否

						</label>

					</div>

				</div>

			</div>

		</div>

		<div class="form-group col-sm-12">

			<input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" />

			<input type="hidden" name="token" value="{$_W['token']}" />

		</div>

	</form>

</div>



{elseif $operation == 'display'}

<div class="main">

	<div class="category">

		<form action="" method="post" onsubmit="return formcheck(this)">

			<div class="panel panel-default">

				<div class="panel-body table-responsive">

					<table class="table table-hover">

						<thead>

							<tr>

								<th style="width:10px;"></th>

								<th style="width:80px;">显示顺序</th>
								<th style="width:20px;">ID</th>

								<th style="width:300px;">分类图标&nbsp;&nbsp;&nbsp;名称</th>

								<th style="width:150px;">状态</th>

								<th style="width:150px;">操作</th>

							</tr>

						</thead>

						<tbody>

						{loop $category $row}

						<tr id="{$row['id']}">

							<td>{if count($children[$row['id']]) > 0}<a href="javascript:;"><i class="fa fa-eye"></i></a>{/if}</td>


							<td><input type="text" class="form-control" name="displayorder[{$row['id']}]" value="{$row['displayorder']}"></td>
							<td>{$row['id']}</td>
							<td>

								&nbsp;&nbsp;<img src="{php echo tomedia($row['thumb']);}" width="25px" height="25px"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$row['name']}

							</td>

							<td>

								{if $row['enabled']==1}

								<span class='label label-success'>显示</span>

								{else}

								<span class='label label-danger'>隐藏</span>

								{/if}

							</td>

							<td>

								<a href="{php echo $this->createWebUrl('classify', array('op' => 'post', 'id' => $row['id']))}" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="bottom" title="编辑"><i class="fa fa-edit"></i></a>&nbsp;&nbsp;

								<a href="{php echo $this->createWebUrl('classify', array('op' => 'delete', 'id' => $row['id']))}" onclick="return confirm('确认删除此分类吗？');return false;" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="bottom" title="删除"><i class="fa fa-times"></i></a>

								<a class='btn btn-default btn-sm' href="{php echo $this->createWebUrl('classify', array('parentid' => $row['id'], 'op' => 'post'))}" title='添加子分类' ><i class="fa fa-plus"></i></a>

							</td>

							

						</tr>

							{loop $children[$row['id']] $child}

							<tr id="zilei{$row['id']}">

								<td></td>

								<td>

									<input type="text" class="form-control col-lg-2" name="displayorder[{$child['id']}]" value="{$child['displayorder']}">

								</td>

								<td>

									<div style="padding-left:50px;height:30px;line-height:30px;background:url('./resource/images/bg_repno.gif') no-repeat -245px -545px;">{$child['name']}

										<img src="{php echo tomedia($child['thumb']);}" width='30' height="30" onerror="$(this).remove()" style='padding:1px;border: 1px solid #ccc;float:left;' />&nbsp;&nbsp;

									</div>

								</td>

								<td>

									{if $child['enabled']==1}

									<span class='label label-success'>显示</span>

									{else}

									<span class='label label-danger'>隐藏</span>

									{/if}

								</td>

								<td>

									<a href="{php echo $this->createWebUrl('classify', array('op' => 'post', 'id' => $child['id']))}" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="bottom" title="编辑"><i class="fa fa-edit"></i></a>&nbsp;&nbsp;

									<a href="{php echo $this->createWebUrl('classify', array('op' => 'delete', 'id' => $child['id']))}" onclick="return confirm('确认删除此分类吗？');return false;" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="bottom" title="删除"><i class="fa fa-times"></i></a>

								</td>

							</tr>

							{/loop}

						{/loop}

						<tr>

							<td></td>

							<td colspan="4">

								<a href="{php echo $this->createWebUrl('classify', array('op' => 'post'))}"><i class="fa fa-plus-sign-alt"></i> 添加新分类</a>

							</td>

						</tr>

						<tr>

							<td></td>

							<td colspan="4">

								<input name="submit" type="submit" class="btn btn-primary" value="提交">

								<input type="hidden" name="token" value="{$_W['token']}" />

							</td>

						</tr>

						</tbody>

					</table>

				</div>

			</div>

		</form>

	</div>

</div>

<script type="text/javascript">

$(document).ready(function(){

	$(".fa-eye").click(function(){

		var name = $(this).parent().parent().parent().attr('id');

		name = '#zilei'+name;

		if($(this).parent().parent().parent().nextAll(name).css("display")=="none"){

			$(this).parent().parent().parent().nextAll(name).show();

		}else{

			$(this).parent().parent().parent().nextAll(name).hide();

		}

	});

});



</script>

{/if}

{template 'common/footer'}

